<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<div class="span12">
    
    <div class="well grey span11">
        <div class="well-header">
            <h5>修改用户</h5>
        </div>

        <div class="well-content">
        <form id="user">
            
            <input type="hidden" name="id" value="${user.id}" />
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">姓名:</label>
	                <div class="field">
	                    <input name="name" class="span12" type="text" value="${user.name }">
	                </div>
                </div>
                <div class="span4">
                    <label class="field_name align_right">年龄:</label>
	                <div class="field">
	                    <input name="age" type="number" min="0" value="${user.age }">
	                </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">邮箱:</label>
	                 <div class="field">
	                     <input name="email" class="span12" type="text" value="${user.email }">
	                 </div>
                </div>
	                <div class="span4">
	                    <label class="field_name align_right">生日:</label>
	                 <div class="field">
                     <input name="birthday" class="span6" type="text" value='<fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd"/>' readonly">
                 </div>
                </div>
            </div>
            
            
             <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">住址:</label>
	                 <div class="field">
	                     <input name="address" style="width:120%" type="text" value="${user.address }">
	                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">性别:</label>
	                 <div class="field">
	                     <label class="radio">
	                            <input type="radio" class="uniform" name="gender" value="0" <c:if test="${user.gender == false }">checked="checked"</c:if>> male
	                        </label>
	                        <label class="radio">
	                            <input type="radio" class="uniform" name="gender" value="1" <c:if test="${user.gender == true }">checked="checked"</c:if>> female
	                        </label>
	                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4" >
                    <label class="field_name align_right">描述：</label>
	                 <div class="field">
	                     <textarea id="description" name="description" cols="80" rows="10" style="resize:none" >${user.description }</textarea>
	                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4" >
	                <div class="field">
	                    <a id="updateUser" href="javascript:void(0);" class="btn red">提交</a>
	                    <a id="cancel" href="javascript:void(0);" class="btn light_blue">取消</a>
	                </div>
                </div>
            </div>
            
            </form>
        </div>
    </div>
</div>

<script>
jQuery(function($){
	$("input[name='birthday']").datetimepicker({
		format:"yyyy-mm-dd",
	    autoclose: true,
	    pickTime: false,
	    minView: '2',
	    todayBtn: true
	});
	
	$("#updateUser").click(function(){
		User.validateUser(function(){
			$.ajax({
				url: "user/update/",
				type: 'post',
				data: $("form").serialize(),
				dataType: "json",
				success: function(json) {
					if (json.code == "0") {
						Fitz.alert("修改成功!", function(){
							Fitz.listPage("user/list");
						});
					} else {
						Fitz.alert(json.message);
					}
				},
				error: function(xhr, textStatus, errorThrown){
					alert(errorThrown);
				}
			});
		});
	});
	
	$("#cancel").click(function(){
		Fitz.listPage("user/list");
	});
})
</script>
